import App from './App'

import uView from '@/uni_modules/uview-ui'
import basicMixin from "@/mixins/basic";
import httpInterceptor from "@/common/js/http.interceptor";
import httpApi from "@/common/js/http.api";
import globalData from "@/globalData";
import store from "@/store";
import InvitationCode from "@/pages/components/InvitationCode";

import Vue from 'vue'
Vue.config.productionTip = false
App.mpType = 'app'
const app = new Vue({
    ...App,
	store
})

Vue.use(uView)
Vue.mixin(basicMixin);
Vue.use(httpInterceptor, app);
Vue.use(httpApi, app);

Vue.component("InvitationCode", InvitationCode);

// 引入uView对小程序分享的mixin封装
let mpShare = require('@/uni_modules/uview-ui/libs/mixin/mpShare.js');
Vue.mixin(mpShare)

Vue.prototype.checkLogin = function(){
	const userInfo = uni.getStorageSync('userInfo')
	if(!uni.$u.test.object(userInfo)){ // 本地没有openid表示未登录
		uni.$u.route('pages/common/wechatLogin')
		return false
	}else{
		let version = userInfo.version
		if(version != globalData.version){
			uni.removeStorageSync('userInfo')
			uni.reLaunch({url:'pages/common/wechatLogin'})
			return false
		}
	}
	return true
}

//小程序更新版本重启应用
const updateManager = wx.getUpdateManager()
updateManager.onCheckForUpdate(function (res) {
  // 请求完新版本信息的回调
  console.log(res.hasUpdate)
})
updateManager.onUpdateReady(function () {
  wx.showModal({
    title: '更新提示',
    content: '新版本已经准备好，是否重启应用？',
    success: function (res) {
      if (res.confirm) {
        // 新的版本已经下载好，调用 applyUpdate 应用新版本并重启
        updateManager.applyUpdate()
      }
    }
  })
})
updateManager.onUpdateFailed(function () {
  // 新版本下载失败
})
app.$mount()

// #ifdef VUE3
import { createSSRApp } from 'vue'
export function createApp() {
  const app = createSSRApp(App)
  return {
    app
  }
}
// #endif
